<?php defined('IN_IA') or exit('Access Denied');?><!DOCTYPE html>
<html lang="en">
<head>
    <?php (!empty($this) && $this instanceof WeModuleSite || 1) ? (include $this->template('common/edithead', TEMPLATE_INCLUDEPATH)) : (include template('common/edithead', TEMPLATE_INCLUDEPATH));?>
    <!--系统 -->
    <!--这个放在最后一切平白安全-->
    <script type="text/javascript" src="./resource/js/require.js?v=20170915"></script>
    <script type="text/javascript">
        //编辑器里使用
        var urobj=[];
    </script>
</head>
<body class="nav-md" style="min-width: 800px">
<div>
    <div class="container xc_edit_from" >
        <div class="main_container" style="overflow-x: hidden;min-height: calc(100vh - 20px);background-color: white;width: 100%;">
            <div class="col-md-12 col-xs-12">
                <div class="x_panel">
                    <ul class="we7-page-tab">
                        <li >
                            <a  href="<?php  echo $this->createWebUrl($do, array('op'=>'list','xtitleb'=>urlencode($xtitleb),'xtitlea'=>urlencode($xtitlea),'new'=>1));?>">
                                <?php  echo $xtitleb;?>- <?php  echo $xtitlea;?>列表  </a></li>
                        <li><a a href="<?php  echo $this->createWebUrl($do, array('op'=>'edit','xtitleb'=>urlencode($xtitleb),'xtitlea'=>urlencode($xtitlea),'new'=>1));?>"><?php  echo $xtitleb;?>- <?php  echo $xtitlea;?>增加</a></li>
                    </ul>
                    <div class="x_content">
                        <br/>
                        <form id="sign-form" class="form-horizontal" role="form" method="post" name="submit">
                            <div class="form-group">
                                <label for="name" class="col-sm-2 control-label">名称</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control"  name="name" id="name" value="<?php  echo $list['name'];?>">
                                    <input type="hidden" name="id" value="<?php  echo $list['id'];?>">
                                    <input type="hidden" name="teacher">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">分类</label>
                                <div class="col-sm-8">
                                    <select  class="form-control js-select2" name="cid" data-select="<?php  echo $list['cid'];?>">
                                        <option value="">请选择分类</option>
                                        <?php  if(is_array($class)) { foreach($class as $index => $item) { ?>
                                        <option value="<?php  echo $item['id'];?>" <?php  if($item['id']==$list['cid']) { ?>selected<?php  } ?> ><?php  echo $item['name'];?></option>
                                        <?php  } } ?>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">封面（750*320）</label>
                                <div class="col-sm-8">
                                    <?php  echo tpl_form_field_image('bimg',$list['bimg']);?>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">学期</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control"  name="xueqi" value="<?php  echo $list['xueqi'];?>">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">课时</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control"  name="keshi" value="<?php  echo $list['keshi'];?>">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">核销次数</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control"  name="can_use" value="<?php  echo $list['can_use'];?>">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">学费</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control"  name="price" value="<?php  echo $list['price'];?>">
                                    <span class="help-block">不填则免费</span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">浏览量</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control"  name="click" value="<?php  echo $list['click'];?>">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">点赞数</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control"  name="zan" value="<?php  echo $list['zan'];?>">
                                </div>
                            </div>
                            <div class="form-group teacher">
                                <label  class="col-sm-2 control-label">任课教师</label>
                                <div class="col-sm-8">
                                    <?php  if($list['teacher']) { ?>
                                    <?php  if(is_array($list['teacher'])) { foreach($list['teacher'] as $index => $item) { ?>
                                    <div class="input-group" style="margin-bottom: 10px;">
                                        <input type="text" class="form-control" name="list" value="<?php  echo $item['name'];?>" data-id="<?php  echo $item['id'];?>">
                        <span class="input-group-btn">
                            <button class="btn btn-default link" type="button" data-toggle="modal" data-target="#sort_link">选择教师</button>
                        </span>
                        <span class="input-group-btn" onclick="parameter.parameter_add(this)">
                            <button class="btn btn-default" type="button"><i class="fa fa-plus"></i></button>
                        </span>
                        <span class="input-group-btn" onclick="parameter.parameter_del(this)">
                            <button class="btn btn-danger" type="button"><i class="fa fa-remove"></i></button>
                        </span>
                                    </div>
                                    <?php  } } ?>
                                    <?php  } else { ?>
                                    <div class="input-group" style="margin-bottom: 10px;">
                                        <input type="text" class="form-control" name="list" value="">
                        <span class="input-group-btn">
                            <button class="btn btn-default link" type="button" data-toggle="modal" data-target="#sort_link">选择教师</button>
                        </span>
                        <span class="input-group-btn" onclick="parameter.parameter_add(this)">
                            <button class="btn btn-default" type="button"><i class="fa fa-plus"></i></button>
                        </span>
                        <span class="input-group-btn" onclick="parameter.parameter_del(this)">
                            <button class="btn btn-danger" type="button"><i class="fa fa-remove"></i></button>
                        </span>
                                    </div>
                                    <?php  } ?>
                                </div>
                            </div>
                            <script>
                                var parameter={
                                    parameter_add:function(objc){
                                        $(objc).parent().after('<div class="input-group" style="margin-bottom: 10px;"> ' +
                                                '<input type="text" class="form-control" name="list" value=""> '+
                                                '<span class="input-group-btn">' +
                                                '<button class="btn btn-default link" type="button" data-toggle="modal" data-target="#sort_link">选择教师</button>' +
                                                '</span>'+
                                                '<span class="input-group-btn" onclick="parameter.parameter_add(this)"> ' +
                                                '<button class="btn btn-default" type="button"><i class="fa fa-plus"></i></button> ' +
                                                '</span> ' +
                                                '<span class="input-group-btn" onclick="parameter.parameter_del(this)"> ' +
                                                '<button class="btn btn-danger" type="button"><i class="fa fa-remove"></i></button> ' +
                                                '</span> ' +
                                                '</div>')
                                    },
                                    parameter_del:function(objc){
                                        if($(objc).parent().siblings().length>0){
                                            $(objc).parent().remove();
                                        }
                                    }
                                }
                            </script>
                            <?php  if($share['status']==1) { ?>
                            <?php  if($share['type']>=1) { ?>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">一级分销佣金</label>
                                <div class="col-sm-8">
                                    <div class="input-group">
                                        <span class="input-group-btn">
                                            <button class="btn btn-default" type="button">消费金额的</button>
                                        </span>
                                        <input type="text" class="form-control" name="share_one" value="<?php  echo $list['share_one'];?>" placeholder="佣金">
                                        <span class="input-group-btn">
                                            <button class="btn btn-default" type="button">%</button>
                                        </span>
                                    </div>
                                </div>
                            </div>
                            <?php  } ?>
                            <?php  if($share['type']>=2) { ?>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">二级分销佣金</label>
                                <div class="col-sm-8">
                                    <div class="input-group">
                                        <span class="input-group-btn">
                                            <button class="btn btn-default" type="button">消费金额的</button>
                                        </span>
                                        <input type="text" class="form-control" name="share_two" value="<?php  echo $list['share_two'];?>" placeholder="佣金">
                                        <span class="input-group-btn">
                                            <button class="btn btn-default" type="button">%</button>
                                        </span>
                                    </div>
                                </div>
                            </div>
                            <?php  } ?>
                            <?php  if($share['type']>=3) { ?>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">三级分销佣金</label>
                                <div class="col-sm-8">
                                    <div class="input-group">
                                        <span class="input-group-btn">
                                            <button class="btn btn-default" type="button">消费金额的</button>
                                        </span>
                                        <input type="text" class="form-control" name="share_three" value="<?php  echo $list['share_three'];?>" placeholder="佣金">
                                        <span class="input-group-btn">
                                            <button class="btn btn-default" type="button">%</button>
                                        </span>
                                    </div>
                                </div>
                            </div>
                            <?php  } ?>
                            <?php  } ?>
                            <div class="form-group">
                                <label  class="col-sm-2 control-label">内容模式</label>
                                <div class="col-sm-8">
                                    <label class="radio inline" style="width: 60px;">
                                        <input type="radio" class="ui-radio" name="content_type" id="content_type1" value="1" <?php  if($list['content_type']==1) { ?>checked<?php  } ?>>多行文本
                                    </label>
                                    <label class="radio inline">
                                        <input type="radio" class="ui-radio" name="content_type" id="content_type2" value="2" <?php  if($list['content_type']==2) { ?>checked<?php  } ?>>编辑器
                                    </label>
                                </div>
                            </div>
                            <div class="form-group">
                                <label  class="col-sm-2 control-label">课程内容</label>
                                <div class="col-sm-8 content_type1">
                                    <textarea rows="5" class="form-control"  name="content" id="content"><?php  echo $list['content'];?></textarea>
                                </div>
                                <div class="col-sm-10 content_type2">
                                    <?php  echo tpl_ueditor('content2',$list['content2']);?>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">首页显示</label>
                                <div class="col-sm-8">
                                    <input type="checkbox" class="js-switch" value="1" name="index"
                                           data-value="<?php  echo $list['index'];?>" data-field="status">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">推荐</label>
                                <div class="col-sm-8">
                                    <input type="checkbox" class="js-switch" value="1" name="tui"
                                           data-value="<?php  echo $list['tui'];?>" data-field="status">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">状态</label>
                                <div class="col-sm-8">
                                    <input type="checkbox" class="js-switch" value="1" name="status"
                                           data-value="<?php  echo $list['status'];?>" data-field="status">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">排序</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control"  name="sort" value="<?php  echo $list['sort'];?>">
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-sm-offset-2 col-sm-10">
                                    <input type="button" name="submit" class="btn btn-default" value="提交">
                                    <a type="button" class="btn btn-default"  href="<?php  echo $this->createWebUrl($do, array('op'=>'list','xtitleb'=> urlencode($xtitleb),'xtitlea'=>urlencode($xtitlea),'new'=>1));?>" >返回</a>
                                    <input id="res" name="res" type="reset" style="display:none;" />
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>

</div>
<div class="modal fade" id="sort_link"><div class="modal-dialog">
    <style>
        #sort_link .modal-body {padding: 10px 15px;}
        #sort_link .tab-pane {margin-top: 5px; min-height: 400px; max-height: 400px; overflow-y: auto;}
        #sort_tab{margin-bottom: 10px;}
    </style>
    <div class="modal-content">
        <div class="modal-header">
            <button data-dismiss="modal" class="close" type="button">×</button>
            <h4 class="modal-title">链接</h4>
        </div>
        <div class="modal-body">
            <iframe width="100%" height="395" frameborder="no" border="0" scrolling="no" allowtransparency="yes" src="<?php  echo url('site/entry/'.$_GPC['do'],array('m'=>$_GPC['m'],'op'=>'teacher'));?>"></iframe>
        </div>
        <div class="modal-footer">
            <button data-dismiss="modal" class="btn btn-default" id="sort_close" type="button">关闭</button>
        </div>
        <script>
            var sort_objc='';
            $(function(){
                $(".sort_customize").on('click','.sort_link',function(){
                    var id=$(this).attr("data-id");
                    if(id==2){
                        $("#sort_link").find("#sort_tab li").eq(1).hide();
                    }else{
                        $("#sort_link").find("#sort_tab li").eq(1).show();
                    }
                    sort_objc=this;
                });
                $("#sort_link").find('#sort_tab a').click(function(e) {
                    $('#tab').val($(this).attr('href'));
                    e.preventDefault();
                    $(this).tab('show');
                });
            });
        </script>
    </div>
</div></div>
<?php (!empty($this) && $this instanceof WeModuleSite || 1) ? (include $this->template('common/editfoot', TEMPLATE_INCLUDEPATH)) : (include template('common/editfoot', TEMPLATE_INCLUDEPATH));?>
<script>
    var objc="";
    if($("#content_type1").is(":checked")){
        $(".content_type2").hide();
        $(".content_type1").show();
    }else if($("#content_type2").is(":checked")){
        $(".content_type1").hide();
        $(".content_type2").show();
    }
    $(function(){
        $("body").on("click",'.link',function(){
            objc=this;
        });
        $("input[name='content_type']").change(function(){
            if($("#content_type1").is(":checked")){
                $(".content_type2").hide();
                $(".content_type1").show();
            }else if($("#content_type2").is(":checked")){
                $(".content_type1").hide();
                $(".content_type2").show();
            }
        });
        $("input[name='submit']").click(function(){
            getjson();
            var data=$(".form-horizontal").serialize();
            $.ajax({
                type:"post",
                url:"<?php  echo url('site/entry/'.$_GPC['do'],array('m'=>$_GPC['m'],'op'=>'savemodel','version_id'=>$_GPC['version_id']));?>",
                data:data,
                dataType:'json',
                success:function(res){
                    if(res.status==1){
                        if($("input[name='id']").val()==""){
                            $("input[name='res']").click();
                            $("body").find(".img-responsive.img-thumbnail").attr("src","");
                        }
                        swal('操作成功!', '操作成功!', 'success');
                    }else{
                        swal('操作失败!', '操作失败!', 'error');
                    }
                }
            })
        });
    })
    function getjson(){
        var teacher=[];
        $(".teacher").find("input[name='list']").each(function(){
            var id=$(this).attr("data-id");
            var name=$(this).val();
            if(id!="" && name!=""){
                var data={id:id,name:name};
                teacher.push(data);
            }
        });
        if(teacher.length>0){
            $("input[name='teacher']").val(JSON.stringify(teacher));
        }
    }
</script>
</body>
</html>